package sqlToGUI.testing.sendingInput;

import java.util.LinkedList;

@SuppressWarnings("unused")
public class HardwareInputGenerator extends Thread{

	/** Buffer for storing the created data */
	private LinkedList <Character>buffer;

	private BatteryDataCreator bdc;
	private CarDataCreator cdc;
	private MotorDataCreator mdc;
	private SolarDataCreator sdc;
	private WeatherDataCreator wdc;

	/** Class Constructor */
	public HardwareInputGenerator(){
		buffer = new LinkedList<Character>();
	}

	/** Start the creation of data */
	public void run(){
		
		/**Initialize the data creators */
		BatteryDataCreator bdc = new BatteryDataCreator(buffer);
		CarDataCreator cdc = new CarDataCreator(buffer);
		MotorDataCreator mdc = new MotorDataCreator(buffer);
		SolarDataCreator sdc = new SolarDataCreator(buffer);
		WeatherDataCreator wdc = new WeatherDataCreator(buffer);
		
		while(true){
			try {
				Thread.sleep(10); bdc.update();
				Thread.sleep(10); cdc.update();
				Thread.sleep(100); mdc.update();
				Thread.sleep(500); sdc.update();
				Thread.sleep(10); wdc.update();
			} catch (InterruptedException e) {
				System.out.println("Data creation stopped!!");
			} catch (StringIndexOutOfBoundsException e) {
				System.out.println("Hardware Input Generator: I created invalid data, sorry...");
			} catch (NullPointerException e) {
				System.out.println("Hardware Input Generator: I created invalid data, sorry...");
			}
		}
	}

	/** Return the reference to the buffer storing the produced data */
	public LinkedList<Character> getBuffer(){
		return buffer;
	}
}
